/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pradoeditor.editors;

import java.util.ArrayList;
import java.util.List;
import pradoeditor.comun.ItemProject;

/**
 *
 * @author jaimeg
 */
public class EditorFactory
{
    static List<ItemProject> itemsOpen = new ArrayList<ItemProject>();

    public static Editor createEditor(ItemProject itemProject)
    {
        Editor editor = null;

        if(getItemProjectOpen(itemProject) == null )
        {
            itemsOpen.add(itemProject);
            
            if(itemProject.getType().equals("page"))
            {
                editor = new EditorPage(itemProject);
            }else if(itemProject.getType().equals("php"))
            {
                editor = new EditorPhp(itemProject);
            }
        }

        return editor;
    }

    private static ItemProject getItemProjectOpen(ItemProject itemProject)
    {
        ItemProject itemProjectReturn = null;

        for(ItemProject i :itemsOpen)
        {
            if (i.getName().equals(itemProject.getName()))
            {
               itemProjectReturn = i;
               break;
            }
        }

        return itemProjectReturn;
    }
}
